<template>
  <DoctorList :isLike="isLike" v-if="isLike"></DoctorList>
  <van-cell v-for="item in knowledgeList" :key="item.id">
    <div class="head">
      <img class="photo" :src="item.creatorAvatar" />
      <div class="info">
        <div class="name">{{ item.creatorName }}</div>
        <p class="intro">
          {{ item.creatorHospatalName }} {{ item.creatorDep }}
          {{ item.creatorTitles }}
        </p>
      </div>
      <button class="attention" @click="onLike(item)">
        {{ item.likeFlag ? "已关注" : "+ 关注" }}
      </button>
    </div>
    <div class="main">
      <div class="caption">{{ item.title }}</div>
      <span class="article" v-html="item.content"></span>
      <div class="imgs">
        <img
          v-for="(url, index) in item.coverUrl"
          :key="index"
          class="img"
          :src="url"
        />
      </div>
    </div>
    <div class="footer">
      <span class="collect">{{ item.collectionNumber }} 收藏</span>
      <span class="discuss">{{ item.commentNumber }} 评论</span>
    </div>
  </van-cell>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'
import { likeKnowledge } from '@/api'
import DoctorList from './doctorList.vue'

defineProps({
  knowledgeList: {
    type: Array,
    default: () => []
  },
  isLike: {
    type: Boolean,
    default: false
  }
})

const emits = defineEmits(['onLikeFlag'])

// 关注操作
const onLike = async (item) => {
  await likeKnowledge({
    id: item.id,
    type: 'knowledge'
  })
  emits('onLikeFlag', item.id)
}
</script>

<style lang="scss" scoped>
::v-deep .van-cell__value {
  text-align: unset;
  color: #c3c3c5;
  .head {
    display: flex;
    align-items: center;
    .photo {
      margin-right: 20px;
      width: 76px;
      border-radius: 50%;
    }
    .info {
      flex: 1;
      line-height: 1.3;
      .name {
        color: #3c3e42;
      }
      .intro {
        width: 400px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 24px;
      }
    }
    .attention {
      margin-right: 30px;
      padding: 0 35px;
      border: 1px solid #16c2a3;
      border-radius: 30px;
      background-color: #fff;
      height: 56px;
      font-size: 24px;
      color: #16c2a3;
    }
  }
  .main {
    padding: 20px 0;
    .caption {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      font-size: 31px;
      color: #121826;
    }
    .article {
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      margin: 10px 0;
      line-height: 2;
      color: #6f6f6f;
      img {
        display: none;
      }
    }
    .imgs {
      display: flex;
      justify-content: space-between;
      .img {
        border-radius: 26px;
        width: 212px;
      }
    }
  }
  .footer {
    font-size: 24px;
    .collect {
      margin-right: 30px;
    }
  }
}
</style>
